<?
layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">模板管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>知识百科管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">模板管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">
		<div class="row">
			<div class="col-lg-5">
				<div class="panel" style="height: 580px; overflow: auto;">
					<div class="panel-heading">分类列表</div>
					<div class="panel-body">
						<ul id="tree" class="ztree" style="width:270px"; overflow:auto;"></ul>
					</div>
				</div>
			</div>
			<div class="col-lg-7">
				<div class="panel" style="height: 580px;overflow: auto;">
					<div class="panel-heading">
						模板管理
						<p style="float: right;">
							<button type="button" onclick="addMenu()"
								class="btn btn-green btn-square" id="savejiedian">新增</button>
							&nbsp;
							<button type="button" onclick="uploadMenu()"
								class="btn btn-green btn-square" id="savejiedian">更新</button>
							&nbsp;
							<button type="button" class="btn btn-green btn-square"
								onclick="deleteMenu()">删除</button>
						</p>
					</div>
					<div style=" padding-left: 5%;">
						<ul id="treeuser" class="ztree" style="width:270px"; overflow:auto;">
							<span class='subtitle' style=" color: #CCC;">数据为空！请选择分类列表</span>
						</ul>
						<input id="menuButtion" type="hidden" class="form-control" />
					</div>
				</div>
			</div>
		</div>
		<!--END CONTENT-->
	</div>
</div>
<?} ?>
<script>
	var parentname =1;
	var ztreeId;
	var ztreeUserId;
	var ztreeUserName;
	//树状结构
	var jursid;
	var roleid;
	$(function() {
		queryRoles();
	});
	var value;
	function getvalue() {
		return value;
	}
	function getZTreeId() {
		return ztreeId;
	}
	function getZtreeUserId() {
		return ztreeUserId;
	}
	function getZtreeUserName() {
		return ztreeUserName;
	}
	var ztreename;
	function getztreename() {
		return ztreename;
	}
	var ztreeSid;
	function getztreeSid() {
		return ztreeSid;
	}
	//查询分类
	function queryRoles() {
		$.ajax({
			type : "post",
			data : {
			
			},
			url : "baikeCategoryQueryJurisdiction.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}
	function drawTree(data) {
		//alert(JSON.stringify(data));
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);

	}
	//分类查询用户
	function onClick(e, treeId, treeNode) {
		ztreeId = treeNode.id;
		ztreename=treeNode.name;
		ztreeSid=treeNode.sid;
		 if(treeNode.children == null){
       		parentname=0;
       	 }else{
         	parentname=1;
        }
		queryUser(ztreeId);
	}
	function queryUser(ztreeId){
		$.ajax({
			type : "post",
			url : "baikeCategoryQueryUser.do",
			data : {
				"id" : ztreeId
			},
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTreeuser,
		});
	}
	function drawTreeuser(data) {
		//alert(JSON.stringify(data));
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
			onClick : onClickUser
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#treeuser"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("treeuser");
		zTree.expandNode(zTree.getNodes()[0], true);
	}
	
	//模板点击事件
	function onClickUser(e, treeId, treeNode) {
	ztreeUserId = treeNode.id;
	ztreeUserName = treeNode.name;
	if(treeNode.children == null){
       		parentname=0;
       	 }else{
         	parentname=1;
        }
	}
	//新增
	function addMenu() {
	/* if(ztreeUserId ==null){
			layer.msg('请选择要新增菜单！');
		}else{ */
		layer.open({
			type : 2,
			area : [ '550px', '550px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : "添加知识",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : [ "baikeCategory_model_add.html", 'no' ],
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	/* } */
};
	//编辑
	function uploadMenu() {
		if (ztreeUserId == null) {
			layer.msg('请选择要编辑的菜单！');
		} else {
			layer.open({
				type : 2,
				area : [ '550px', '550px' ],
				fix : false, //不固定
				scrollbar : false,
				shadeClose : true,
				move : false,
				title : "编辑知识",
				skin : 'layui-layer-rim', //加上边框
				btn : [ '保存 ', '关闭' ],
				content : [ "baikeCategory_model_upload.html", 'no' ],
				yes : function(index, layer) {
					var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					iframeWin.save();
				},
				cancel : function(index) {
				}
			});
		}
	};
	//删除
	function deleteMenu() {
		if (ztreeUserId == null) {
			layer.msg('请选择要删除菜单！');
		} else {
		if(parentname == 0){
				if (confirm("是否确认删除！！")) {
					$.ajax({
						type : "post",
						url : "baikeTemplateDeleteMent.do",
						data : {
							"id" : ztreeUserId
						},
						dataType : "json",
						beforeSend : function(XMLHttpRequest) {
						},
						success : function(data) {
							ztreeUserId=0;
							queryUser(ztreeId);
							layer.msg('删除成功！');
						},
					});
				}
			} else{
				alert("有子分类不允许删除");
			}
	}
}
</script>